package cn.edu.jsu.official.config;

import cn.edu.jsu.official.utils.UploadPathUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Mo
 * @createTime 2022/4/27 22:11
 * @description
 */
@Slf4j
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
    /**
     * 文件上传路径
     */
    @Value("${file.staticAccessDocumentPath}")
    private String staticAccessDocumentPath;
    /**
     * 图片上传路径
     */
    @Value("${file.staticAccessImagesPath}")
    private String staticAccessImagesPath;

    /**
     * 虚拟路径映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        ArrayList<String> systemRoot = UploadPathUtil.getSystemRoot();
        log.info("systemRoot: " + systemRoot);
        //  在yaml配置文件中读取路径
        //  registry.addResourceHandler(staticAccessDocumentPath).addResourceLocations("file:"+systemRoot.get(0));
        registry.addResourceHandler(staticAccessImagesPath).addResourceLocations("file:"+systemRoot.get(1));
        super.addResourceHandlers(registry);
    }
}
